import 'package:flutter/material.dart';
import '../../tools/loginscreen.dart';
import '../../tools/smscontroller.dart';

class LikedTab extends StatefulWidget {
  @override
  _LikedTabState createState() => _LikedTabState();
}

class _LikedTabState extends State<LikedTab> {
  @override
  Widget build(BuildContext context) {
    final orientation = MediaQuery.of(context).orientation;

    return ValueListenableBuilder<bool>(
      valueListenable: GlobalState.isLoggedIn,
      builder: (context, isLoggedIn, child) {
        return Container(
          color: Colors.white,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // 可导入图片区域
              Container(
                height: orientation == Orientation.portrait ? 150 : 100,
                width: orientation == Orientation.portrait ? 150 : 100,
                decoration: BoxDecoration(
                  color: Colors.grey.shade300,
                  image: DecorationImage(
                    image: AssetImage('lib/assets/logo.png'),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              SizedBox(height: 16),
              Text(
                isLoggedIn
                  ? '什么都没有哦Σ(っ °Д °;)っ'
                  : '登录后即可查看内容，',
                style: TextStyle(color: Colors.black),
              ),
              if (!isLoggedIn)
                GestureDetector(
                  onTap: () {
                    showModalBottomSheet(
                      isScrollControlled: true, // 使上拉框在键盘弹出时漂浮在上方
                      context: context,
                      builder: (BuildContext context) => AddTaskScreen(),
                    ).then((_) => setState(() {})); // 登录后重新构建界面
                  },
                  child: Text('去登录', style: TextStyle(color: Colors.blue)),
                ),
            ],
          ),
        );
      },
    );
  }
}
